package tmproject.hlhj.fhp.cartrans

import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.mymvp.BaseMVP
import com.example.mymvp.BasePresenter
import com.example.mymvp.BaseView
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.disposables.Disposable

/**
 * Created by Administrator on 2018/8/23/023.
 */
abstract class BaseFgm<V:BaseView,P:BasePresenter<*,V>>:Fragment(),BaseMVP<V,P> {
    private var  compositeDisable: CompositeDisposable?=null
    lateinit var rootView:View
    var presenter:P?=null
    var footNotingView:View?=null
    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        rootView=inflater?.inflate(getContentId(),null)!!
        footNotingView=LayoutInflater.from(context).inflate(R.layout.lo_foot_nodata,null)

        presenter=createPresenter()

        presenter?.let {
            it.createModule()
            it.bindView(bindView())

            it.initView()
            it.setListener()
            it.logicStart()
        }
        /**
         * 列表的足布局
         */

        return rootView
    }
    override fun onDestroy() {
        presenter?.destory()
        compositeDisable?.dispose()
        super.onDestroy()
    }
    open fun addDisable(disable: Disposable){
        if (compositeDisable==null){
            compositeDisable=CompositeDisposable()
        }
        compositeDisable?.add(disable)
    }

    abstract fun getContentId():Int
    override fun setUserVisibleHint(isVisibleToUser: Boolean) {
        super.setUserVisibleHint(isVisibleToUser)
        if (isVisibleToUser){
            resum()
        }else{

        }
    }
    open fun resum(){

    }
}